<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div style="text-align:center;">
	<table style="width:100%; border-collapse:separate; border-spacing:20px;">
		<tr>
			<td style="text-align:right;">
				<label for="user_modify_userName">姓名：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_userName">
			</td>
			<td style="text-align:right;">
				<label for="user_modify_userCode">编码：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_userCode">
			</td>
		</tr>
		<tr>
			<td style="text-align:right;">
				<label for="user_modify_email">邮箱：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_email">
			</td>
			<td style="text-align:right;">
				<label for="user_modify_company">机构：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_company">
			</td>
		</tr>
		<tr>
			<td style="text-align:right;">
				<label for="user_modify_company_child1">子机构：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_company_child1"/>
			</td>
			<td style="text-align:right;">
				<label for="user_modify_company_child2">部门：</label>
			</td>
			<td style="text-align:left;">
				<input id="user_modify_company_child2"/>
			</td>
		</tr>
	</table>
	<script type="text/javascript">
		$(function() {
			initUserModifyTag();
			$("#user_modify_company").combobox({
				onClick : function(record) {
					com1SelectOnChangeEvent(record.comId);
				}
			});
			$("#user_modify_company_child1").combobox({
				onClick : function(record) {
					com2SelectOnChangeEvent(record.comId);
				}
			});
		})
		
		/** 初始化修改页面的各个控件  */
		function initUserModifyTag() {
			var selectedUser = $("#user_list_table").datagrid("getSelected");
			$("#user_modify_userCode").textbox({
				disabled : true,
				value : selectedUser.userCode
			});
			$("#user_modify_userName").textbox({
				value : selectedUser.userName
			});
			$("#user_modify_email").textbox({
				value : selectedUser.email
			});
			$("#user_modify_company").combobox({
				editable : false
			});
			$("#user_modify_company_child1").combobox({
				editable : false
			});
			$("#user_modify_company_child2").combobox({
				editable : false
			});
			
			var url = "${pageContext.request.contextPath}/system/selectComById";
			$.post(url,
				{"comId" : selectedUser.comId},
				function(data) {
					var grade = data.grade;
					if (grade == "01") {
						initComSelect("user_modify_company", data, selectedUser.comId);
					} else if (grade == "02") {
						initComSelect("user_modify_company_child1", data, selectedUser.comId);
						initComSelect("user_modify_company", data.comMap, ((data.comList)[0]).parentComId);
					} else if (grade == "03") {
						initComSelect("user_modify_company_child2", data, selectedUser.comId);
						initComSelect("user_modify_company_child1", data.comMap, ((data.comList)[0]).parentComId);
						initComSelect("user_modify_company", data.comMap.comMap, ((data.comMap.comList)[0]).parentComId);
					}
				},"JSON"
			);
		}
		
		/** 初始化机构下拉框  */
		function initComSelect(ID, data, currComId) {
			$("#"+ID).combobox({
				valueField : "comId",
				textField : "comName",
				data : data.comList,
				editable : false,
				onLoadSuccess : function() {
					$("#"+ID).combobox("setValue", currComId);
				}
			});
		}
		
		/** 第一级机构下拉框的onChange事件  */
		function com1SelectOnChangeEvent(newValue) {
			$("#user_modify_company_child1").combobox("loadData", {});
			$("#user_modify_company_child2").combobox("loadData", {});
			$("#user_modify_company_child1").combobox("clear");
			$("#user_modify_company_child2").combobox("clear");
			var url = "${pageContext.request.contextPath}/system/selectCompanyByCondition";
			$.post(url,
				{"parentComId" : newValue},
				function(data) {
					if (data && data.length > 0) {
						$("#user_modify_company_child1").combobox({
							valueField : "comId",
							textField : "comName",
							editable : false,
							data : data
						});
						$("#user_modify_company_child1").combobox("clear");
					}
				},"JSON"
			);
		}
		
		/** 第二级机构下拉框的onChange事件  */
		function com2SelectOnChangeEvent(newValue) {
			$("#user_modify_company_child2").combobox("loadData", {});
			$("#user_modify_company_child2").combobox("clear");
			var url = "${pageContext.request.contextPath}/system/selectCompanyByCondition";
			$.post(url,
				{"parentComId" : newValue},
				function(data) {
					if (data && data.length > 0) {
						$("#user_modify_company_child2").combobox({
							valueField : "comId",
							textField : "comName",
							editable : false,
							data : data
						});
						$("#user_modify_company_child2").combobox("clear");
					}
				},"JSON"
			);
		}
	</script>
</div>